

package tkatva.consulting.jmxpoller

import scala.xml.XML
import scala.xml._
import scala.collection.mutable.ListBuffer

/*
 * Author Tuomas Katva
 * 
 * 17.4.2012 -> Add method to change adminUsr and adminPword elements
 * also add method to change ServiceMixUrl-element
 * 
 */

class CfgHelper {

  
  var xmlPath : String = "";
  
  def readFromFile() : Elem = {
    XML.loadFile(xmlPath)
  }
  
  def getServicemixUrl(pathParam : String) : String = {
    xmlPath = pathParam
    var root = readFromFile();
    

    var jmxUrl : String = "";
    
    root.\("jmxUrl").foreach(urlNode => jmxUrl = urlNode.text)
    
    jmxUrl  

  }
  
  def getLoginUsrNameAndPword(pathParam : String) : (String, String) = {
    xmlPath = pathParam
    var root = readFromFile();
    
    var adminUsr : String = ""
    
    root.\("adminUsr").foreach(urlNode => adminUsr = urlNode.text)
    
    var adminPword : String = ""
    
    root.\("adminPword").foreach(urlNode => adminPword = urlNode.text)
    
    val retVal = (adminUsr,adminPword)
    
    return retVal
  }
  
  def getUsrNameAndPword(pathParam : String) : (String, String) = {
    xmlPath = pathParam
    var root = readFromFile();
    

    var jmxUsr : String = "";

    root.\("jmxUsr").foreach(urlNode => jmxUsr = urlNode.text)
   
    
    var jmxPword : String = "";
    
    root.\("jmxPword").foreach(urlNode => jmxPword = urlNode.text)
   
    
    val retVal = (jmxUsr,jmxPword)
    return retVal
  }
  
  def getFilters(pathParam : String) : List[String] = {
    xmlPath = pathParam
    var root = readFromFile();
    val filterBuf = new ListBuffer[String]
    root.\\("jmxFilter").foreach(urlNode => filterBuf += urlNode.text)
    
    return filterBuf.toList
  }
  
  
  
}
